package com.webserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class WebServer {
	
	/**
	 * 启动web服务器
	 */
	public void serverStart(int port){
		try {
			//对80端口进行监听
			ServerSocket serverSocket=new ServerSocket(port);
			//等待来连接socket
			while(true){
				Socket socket= serverSocket.accept();//等待接受队列
				//启动线程来处理
				new Processor(socket).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		int port =80;
		if(args.length==1){
			 port =Integer.parseInt(args[0]);
		}
		//生成web实例
		new WebServer().serverStart(port);
	}

}
